﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.AudioPlayer.Core;
using UtilZ.Dotnet.AudioPlayer.Native;
using UtilZ.Dotnet.AudioPlayer.Player;
using UtilZ.Dotnet.Ex.Base;
using UtilZ.Dotnet.Ex.Log;

namespace ConAppCore
{
    internal class TestMathEx
    {
        internal static void Test()
        {
            //var ret11 = double.IsNormal(0d);
            //var ret12 = double.IsNormal(-1d);
            //var ret13 = double.IsNormal(2d);
            //var ret2 = double.IsNormal(double.MaxValue);
            //var ret3 = double.IsNormal(double.MinValue);
            //var ret4 = double.IsNormal(double.NaN);
            //var ret5 = double.IsNormal(double.NegativeInfinity);
            //var ret6 = double.IsNormal(double.PositiveInfinity);

            //var ret211 = double.IsSubnormal(0d);
            //var ret212 = double.IsSubnormal(-1d);
            //var ret213 = double.IsSubnormal(2d);
            //var ret21 = double.IsSubnormal(0d);
            //var ret22 = double.IsSubnormal(double.MaxValue);
            //var ret23 = double.IsSubnormal(double.MinValue);
            //var ret24 = double.IsSubnormal(double.NaN);
            //var ret25 = double.IsSubnormal(double.NegativeInfinity);
            //var ret26 = double.IsSubnormal(double.PositiveInfinity);

            //var ret = Math.Log10(0d);
            //TestBufferBlockCopy();
            TestGCDAndLCM();
        }


        private static void TestGCDAndLCM()
        {
            TestGCD(1, 2);
            TestGCD(3, 6);
            TestGCD(6, 2);
            TestGCD(10, 10);
            TestGCD(7, 8);

            Console.WriteLine("---------------------");

            TestLCM(1, 2);
            TestLCM(3, 6);
            TestLCM(6, 2);
            TestLCM(10, 10);
            TestLCM(7, 8);
        }

        private static void TestLCM(int a, int b)
        {
            int ret = MathEx.LCM(a, b);
            Console.WriteLine($"“{a}”和“{b}”最小公倍数为：{ret}");
        }

        private static void TestGCD(int a, int b)
        {
            int ret = MathEx.GCD(a, b);
            Console.WriteLine($"“{a}”和“{b}”最大公约数为：{ret}");
        }


       

        private static void TestBufferBlockCopy()
        {
            //注Buffer.BlockCopy操作的是字节,所以拷贝数据为非byte类型时,必须乘以数据类型所占字节数
            var srcArr = new double[] { 1, 2, 3, 4, 5 };
            var dstArr = new double[srcArr.Length];
            var mul = sizeof(double);
            Buffer.BlockCopy(srcArr, 0 * mul, dstArr, 0 * mul, 3 * mul);

            var srcArr2 = new byte[] { 1, 2, 3, 4, 5 };
            var dstArr2 = new byte[srcArr.Length];
            Buffer.BlockCopy(srcArr2, 0, dstArr2, 0, 3);
        }


    }

  
}
